package receiver;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ita.ios.jms.protocol.JmsProtocol;

import po.MerchantAudit;
import service.MerchantAuditManager;
import vo.MerchantAuditVo;

 
@Component("merchantAuditListener")
public class MerchantAuditListener implements MessageListener {

	@Autowired
	private MerchantAuditManager merchantAuditManager; 
	
	@Override
	public void onMessage(Message message) {
		try {
			String text = ((TextMessage)message).getText();
			System.out.println("merchantAuditListener接收到消息:" + text);
//			MerchantAuditVo merchantAudit = (MerchantAuditVo) JmsProtocol.deserializeMerchantGrace(text, MerchantAuditVo.class);
			MerchantAudit merchantAudit = (MerchantAudit) JmsProtocol.deserializeObject(text, MerchantAudit.class);
			if(merchantAudit != null){
//				merchantAuditManager.addMerchantAudit(merchantAudit);
				merchantAuditManager.addMerchantAudit(merchantAudit);
//				merchantAuditManager.addMerchantAudit(new MerchantAudit(merchantAudit.getMerchant().getmId(), merchantAudit.getCreateDate()));
				System.out.println("add the merchantAudit success!!!");
			}
			} catch (JMSException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
}
